package com.itheima.d4_hashcode;

import java.util.Objects;

public class Student {
    private String name;
    private int age;
    private String address;
    private String phone;

    public Student() {
    }

    public Student(String name, int age, String address, String phone) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.phone = phone;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return address
     */
    public String getAddress() {
        return address;
    }

    /**
     * 设置
     * @param address
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * 获取
     * @return phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * 设置
     * @param phone
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + ", address = " + address + ", phone = " + phone + "}";
    }

    @Override
    public boolean equals(Object o) {
        //首先跟自己传过去的对象相比 如果是同一个对象 就返回true
        if (this == o) return true;
        //如果o为空或者o的类型和当前对象不一致 就返回false
        if (o == null || getClass() != o.getClass()) return false;
        //比较两个对象的内容是否一致
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name) && Objects.equals(address, student.address) && Objects.equals(phone, student.phone);
    }

    @Override
    public int hashCode() {
        //如果 不同对象 但是内容相等 我们就重写 返回相同的哈希值
        return Objects.hash(name, age, address, phone);
    }
}
